<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <base href="${pageContext.request.contextPath}/"/>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/style.css"/>
    <script type="text/javascript" src="./Js/jquery.js"></script>
    <script type="text/javascript" src="./Js/bootstrap.js"></script>
    <script type="text/javascript" src="./Js/ckform.js"></script>
    <script type="text/javascript" src="./Js/common.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }

        .option-button:hover {
            color: red;
        }
    </style>
</head>
<body>
<form class="form-inline definewidth m20" action="/menu/search?currentPage=1&pageSize=10" method="post">
    名称： <input type="text" name="name" id="name" class="abc input-default" placeholder="请输入名称">&nbsp;&nbsp;
    <button type="submit" id="search" class="btn btn-primary">查询</button>
    &nbsp;&nbsp;
    <button type="button" class="btn btn-success" id="addnew">新增菜单</button>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>id</th>
        <th>权限名称</th>
        <th>访问地址</th>
        <th>父菜单ID</th>
        <th>操作</th>
    </tr>
    </thead>
    <c:forEach items="${pageEnd.rows}" var="menu">
        <tr>
            <td>${menu.id}</td>
            <td>${menu.name}</td>
            <td>${menu.link}</td>
            <td>${menu.pid}</td>
            <td>
                <a class="option-button" href="/menu/edit?id=${menu.id}">编辑</a>
                |<a class="option-button" style="cursor:pointer" onclick="del(${menu.id})">删除</a>
                    <%--                |<a class="option-button" href="/menu/show?id=${menu.id}">查看</a>--%>
            </td>
        </tr>
    </c:forEach>
</table>
<div class="inline pull-right page">
    ${pageEnd.total}条记录 ${pageEnd.currentPage}/ ${pageEnd.totalPage}页
    <c:if test="${pageEnd.currentPage!=1}">
        <a href='/menu/search?currentPage=1&pageSize=10'>首页</a>
    </c:if>
    <c:if test="${pageEnd.currentPage!=1}">
        <a href='/menu/search?currentPage=${pageEnd.currentPage-1}&pageSize=10'>上一页</a>
    </c:if>
    <c:if test="${pageEnd.currentPage!=pageEnd.totalPage}">
        <a href='/menu/search?currentPage=${pageEnd.currentPage+1}&pageSize=10'>下一页</a>
    </c:if>
    <c:if test="${pageEnd.currentPage!=pageEnd.totalPage}">
        <a href='/menu/search?currentPage=${pageEnd.totalPage}&pageSize=10'>尾页</a>
    </c:if>
</div>
</body>
</html>
<script type="text/javascript">
    $("#addnew").click(function () {
        window.location.href = "/menu/addMenu";
    });

    function del(id) {
        var ids = [];
        ids = id;
        var param = "ids=" + ids;
        if (confirm("你确定要删除吗？")) {
            $.ajax({
                url: "/menu/delete?ids=" + ids,
                type: "post",
                async: true,
                data: param,
                success: function (res) {
                    if (res.success) {
                        alert("删除成功！")
                        window.location.href = "/menu/list";
                    } else {
                        alert(res.message);
                    }
                },
                error: function (e) {
                    alert(e);
                }
            });
        } else {
            //can not delete
        }
    };
</script>